import os
import json

# items = {}
# if os.path.exists('iconmap.json'):
#     jsonContent = None
#     with open('recipe.json', 'rb') as f:
#         jsonContent = json.load(f)
#     for item in jsonContent['items']:
#         items[item['image']] = item['name']

items = {}
with open('iconmap.json', 'rb')as f:
    jsonContent = json.load(f)
    for item in jsonContent:
        items[item[0]] = item[1]

# print(items)
# exit()

iconspaths = os.listdir('物品查看器/Resource/')

iconmap = []
for iconname in iconspaths:
    enname = os.path.splitext(iconname)[0]
    cnname = ''
    if enname in items:
        cnname = items[enname]
    names = [enname, cnname]
    iconmap.append(names)

with open('iconmap.json', 'w', encoding='utf-8') as f:
    json.dump(iconmap, f, indent=4, separators=(',', ':'), ensure_ascii=False)
